package net.lookyou.boot.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lookyou.boot.demo.entity.User;
import net.lookyou.boot.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/getData")
    @ResponseBody
    public String test(){
        return "index";
    }

    @PostMapping("/user/get1")
    public User getOne(int id) {

        return userService.getOne(id);
    }


    /**
     * QueryWrapper add 的应用
     * @param user
     * @return
     */
    @PostMapping("/user/get2")
    public User getOne2(@RequestBody User user) {
        return  userService.userDetail(user);
    }

    /**
     * QueryWrapper or 的应用
     * @param user
     * @return
     */
    @PostMapping("/user/get3")
    public List<User> get3(@RequestBody User user) {
        return  userService.selectList(user);
    }


    /**
     * QueryWrapper 分页
     * @param pageNo
     * @return
     */
    @PostMapping("/user/get4")
    public Page<User> get4(int pageNo, int pageSize) {
        return  userService.selectPage(pageNo, pageSize);
    }
}